package com.union.widget.time;

/**
 * The simple Array wheel adapter
 * 
 * @param <T>
 *            the element type
 */
public class ArrayWheelAdapter<T> implements WheelAdapter {

    /** The default items length */
    public static final int DEFAULT_LENGTH = -1;

    // items
    private T items[];
    // length
    private int length;

    private String values = null;
    /**
     * Constructor
     * 
     * @param items
     *            the items
     * @param length
     *            the max items length
     */
    public ArrayWheelAdapter(T items[], int length) {
        this.items = items;
        this.length = length;
    }

    public void setValues(String values) {
        this.values = values;
    }

    /**
     * Contructor
     * 
     * @param items
     *            the items
     */
    public ArrayWheelAdapter(T items[]) {
        this(items, DEFAULT_LENGTH);
    }

    @Override
    public String getItem(int index) {
        if (index >= 0 && index < items.length) {
            setValues(items[index].toString());
            return items[index].toString();
        }
        return null;
    }

    // 返回当前选中的�?
    public String getValues() {
        return values;
    }

    @Override
    public int getItemsCount() {
        return items.length;
    }

    @Override
    public int getMaximumLength() {
        return length;
    }

}
